package br.com.exceptiongroup.chatexception.service;

import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import br.com.exceptiongroup.chatexception.model.Usuario;

@Service(value="usuarioService")
public class UsuarioService extends BaseMongoService<Usuario> implements UserDetailsService{

	public UsuarioService() {
		super(Usuario.class);
	}

	@Override
	public UserDetails loadUserByUsername(String username)
			throws UsernameNotFoundException {
		Query query = new Query();
		query.addCriteria(Criteria.where("username").is(username));
		
		return template.findOne(query, Usuario.class);
	}
	
}